<template>
  <div class="detail">
    <Myheader>
      <template #center>kiana 快来听歌歌咯 (*^▽^*)</template>
      <template #os>听哪首歌呢 emmm...</template>
    </Myheader>
    <div class="container">
      <div class="left">vae</div>
      <div class="right" ref="right">
        <div class="top">
          <div class="pic" :class="topFixed ? 'top-fixed' : ''"
            :style="{ backgroundImage: 'url('+ img +')' , backgroundSize: 'cover'}"
          >
            <div class="page-logo">
              <!-- <div :class="topFixed ? 'top-fixed' : ''"></div> -->
              <i class="el-icon-arrow-left" @click="$router.go(-1)"></i>
              <i class="el-icon-arrow-right" @click="$router.go(1)"></i>
            </div>
            <div class="singer-name">
              {{ singerName }}
            </div>
          </div>      
        </div>
        <div class="song-list">
          <h3>热门歌曲</h3>
          <div class="song">
            <div class="title">
              <div>歌曲</div>
              <div>专辑</div>
              <div>时长</div>
            </div>
            <div class="song-item" v-for="(item, index) in songList" :key="index"
              @click="addMusic({ list: songList, idx: index })"
            >
              <div class="name">{{ item.name }}</div>
              <div class="album">{{ item.album }}</div>
              <div class="time">{{ item.duration | timeFilter(2) }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSongListById } from '@/service/music';
import imgMixin from '@/mixins/imgMixin';
import _ from 'lodash';
import { mapActions } from 'vuex';

export default {
  mixins: [ imgMixin ],
  props: ['singerId'],
  data() {
    return {
      singerName: '',
      songList: [],
      topFixed: false,
      singerBg: '',
      img: '',
    };
  },
  methods: {
    ...mapActions('player', ['addMusic']),
    async getSongListByIdData() {
      const res = await getSongListById(this.singerId);
      const { code, result } = res || {};
      if (code) return;
      this.songList = result?.songs || [];
    },
  },
  mounted() {
    this.getSongListByIdData();
    this.$refs.right.addEventListener('scroll', _.throttle((e) => {
      if (e.target.scrollTop >= 190) {
        this.topFixed = true;
      } else {
        this.topFixed = false;
      }
    }, 300));
    this.singerName = this.$route.query.name
    this.img = imgMixin.filters.imgFilter(this.singerId);
    const queryParams = new URLSearchParams(window.location.search);
    console.log(queryParams);
    console.log(queryParams.get('name'))
  },
};
</script>

<style lang="scss" scoped>
.detail {
  height: 100%;
  .container {
    display: flex;
    // height: calc(100% - 60px);
    height: 80vh;
    .left {
      width: 200px;
      height: calc(100% - 60px);
      background-color: skyblue;
    }
    .right {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow-y: scroll;
      margin-bottom: 80px;
      .top {
        .pic {
          width: 100%;
          height: 240px;
          overflow: hidden;
          .page-logo {
            position: fixed;
            top: 70px;
            left: 230px;
            color: #fff;
            i {
              cursor: pointer;
              &:hover {
                color: palegreen;
              }
            }
          }
          .singer-name {
            margin-top: 150px;
            margin-left: 30px;
            color: #fff;
            font-size: 30px;
            font-weight: 600;
          }
        }
        .top-fixed {
          height: 80px;
          position: fixed;
        }       
      }
      .song-list {
        padding-left: 20px;
        // height: 360px;
        height: calc(100% - 300px);

        .song {
          .title {
            display: flex;
            height: 30px;
            div {
              &:nth-of-type(1) {
                width: 60%;
              }
              &:nth-of-type(2) {
                width: 30%;
              }
              &:nth-of-type(3) {
                width: 10%;
              }
            }
          }
          .song-item {
            display: flex;
            align-items: center;
            height: 30px;
            &:hover {
              background-color: rgba(50, 50, 50, .2);
            }
            .name {
              width: 60%;
              box-sizing: border-box;
              padding-left: 20px;
            }
            .album {
              width: 30%;
            }
            .time {
              width: 10%;
            }
          }
        }
      }
      transition: all .5;
    }
  }
}
</style>
